package com.atguigu.study.controller;

import dev.langchain4j.model.openai.OpenAiChatModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Taeyang
 * @date 2025/5/7
 */
@RestController
@Slf4j
public class HelloLangChain4JController {

    private final OpenAiChatModel openAiChatModel;

    @Autowired
    public HelloLangChain4JController(OpenAiChatModel openAiChatModel) {
        this.openAiChatModel = openAiChatModel;
    }

    @GetMapping("/langchain4j/chat")
    public String model(@RequestParam(value = "message", defaultValue = "你好") String message) {
        String result = openAiChatModel.chat(message);
        System.out.println("通过langchain4j调用qwen-turbo模型返回结果：\n" + result);
        return result;
    }
}
